<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/commons/jsp/taglibs.jsp"%>
<%@taglib uri="http://www.framework.com/taglib/tree" prefix="tree"%>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<style type="text/css">
	li{
		padding-top:8px;
	}
</style>
<form name="addCancelDataForm" id="addCancelResonForm" method="post" action="" >
	<input type="hidden" name="projectId" value="${projectId}"/>
	<input type="hidden" name="status" value="${status}"/>
    <!--  <input type="hidden" name="type" value="${type}"/>-->
	<input type="hidden" name="budgetMenuData" id="budgetMenuData" value=""/>
	<table class="infoTable">
		<tbody>
			<tr>
			<th align="right" width="15%">附件</th>
			<td style="border-right: none" width="35%">
				<div id="fileQueue" style="margin: 10px 0px 0px 10px">
					<input type="file" name="uploadify" id="uploadify" data-options="required:true"/>
					<p style="color: #aaaaaa;width: auto">
		1、按住Ctrl可选择多个文件上传;<br/>
		2、可上传jpg,png,gif,bmp,pdf,zip,rar类型文件<br/>
		</p>
				</div>
			</td>
			<td style="border-left: none" colspan="2">
				<%-- <c:forEach items="${resList}" var="res">
					<c:if test="${res.functionFlog==20}">
						<div><a class="easyui-linkbutton" href="${ctx}/business/projectmanage/fileView?resId=${res.id}" >${res.oldName}</a> <span style="cursor: pointer;" onclick="deleteFile(this,'${res.id}');"><img src="${ctx }/commons/themes/icons/cancel.png"/></span></div>
					</c:if>
				</c:forEach> --%>
			</td>
		</tr>
		</tbody>
	</table>		
</form>

<script type="text/javascript">
	$(function(){
	    parent.$('#addEntityBt').hide();
		var resIds = "";
		<c:forEach items="${resList}" var="res">
		resIds += ",${res.id}";
		</c:forEach>
		$('#budgetMenuData').val(resIds);
		$("#uploadify").uploadify({
			'height'        : 27,   
            'width'         : 80,    
            'buttonText'    : '选择附件',
            'queueID': 'fileQueue',//队列的ID
            'queueSizeLimit':5,// 附件附列长度
			'swf': '${ctx}/commons/js/uploadify/uploadify.swf',
			'uploader':'${ctx}/business/projectmanage/upload;jsessionid=${pageContext.session.id}?functionFlog=20',// 上传时请求的后台处理的controller
			'cancelImg': '${ctx}/commons/js/uploadify/uploadify-cancel.png',
			'method':'post',  
			'folder': '',
			'preventCaching' : true,
			'fileTypeExts' :'*.jpg;*.png;*.gif;*.bmp;*.pdf;*.zip;*.rar;',
			'auto': true,
			'multi': true,//是否可多选
			'removeCompleted' : false,
			'successTimeout' : 55555,
			'onUploadSuccess':function(file, data, response){
				$('#' + file.id).find('.data').html(' 上传完毕');
				$('#budgetMenuData').val($('#budgetMenuData').val() + "," + data);
				var cancel=$('#fileQueue .uploadify-queue-item[id="' + file.id + '"]').find(".cancel a");
				if (cancel) {
				   cancel.attr("rel", data);
				   cancel.click(function () {
					   var cancelData = cancel.attr("rel");
		               var  budgetMenuData = $('#budgetMenuData').val();
		               var index = budgetMenuData.indexOf(","+cancel.attr("rel"))
		               if(index != -1){
		            	   budgetMenuData = budgetMenuData.replace(","+cancelData,"");
		            	   $('#budgetMenuData').val(budgetMenuData);
		               }
				   });
				}
			},
			'onSelectError':function(file, errorCode, errorMsg){
				switch(errorCode) {
					case -110:
						//this.queueData.errorMsg="文件 ["+file.name+"] 大小超出系统限制的"+$('#file_upload').uploadify('settings','fileSizeLimit')+"大小！";
						this.queueData.errorMsg='所选文件大小超出系统限制!';
						break;
					case -120:
						//this.queueData.errorMsg="文件 ["+file.name+"] 大小异常！"
						this.queueData.errorMsg='所选文件大小异常!';
						break;
					case -130:
						//this.queueData.errorMsg="文件 ["+file.name+"] 类型不正确！"
						this.queueData.errorMsg='所选文件类型不正确!';
						break;
				}
			},
			'onCancel' : function(file){
				alert(file);
			},
			onClose : function(){// 解决IE浏览器中无法移除object标签，导致上传插件的flash无法使用，所有的dialog都会出现问题
				top.$("#uploadify").uploadify('destroy');//销毁文件上传对象....
				top.$("#dealDeclareUpload").uploadify('destroy');//销毁文件上传对象....
				top.$("#uploadify").uploadify('destroy');//销毁文件上传对象....
				if(top.$('#'+paramObj.showDialogId).find("object").length > 0){
					var fileQueue = top.window.document.getElementById("fileQueue");
					fileQueue.innerHTML = "";
					fileQueue.parentNode.removeChild(fileQueue);
				}
				afterClosed();
			}
		});
	});
	function deleteFile(v,resId){
		var parent = v.parentNode;
		parent.parentNode.removeChild(parent);
		var  budgetMenuData = $('#budgetMenuData').val();
        var index = budgetMenuData.indexOf(","+resId)
        if(index != -1){
     	   budgetMenuData = budgetMenuData.replace(","+resId,"");
     	   $('#budgetMenuData').val(budgetMenuData);
        }
	}
	
</script>
		